﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace OrderM
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)//AddOrEdit
        {
            if (Form1.AddorEdit == 0)
            {
                Order o = new Order();

                o.Id = Convert.ToInt32(textBox1.Text);
                o.customer = (textBox2.Text);
                o.StuffType = (textBox3.Text);
                o.price = Convert.ToDouble(textBox4.Text);

                bool flag = Form1.service.AddOrder(o);
                if (flag)
                    MessageBox.Show("Successfully add order");
                else
                    MessageBox.Show("Fail add.Order repeated");
                textBox1.Clear();
                textBox2.Clear();
                textBox3.Clear();
                textBox4.Clear();
            }
            else
            {
                Order temp = Form1.order;
                DialogResult RSS = MessageBox.Show(this, "Confirm to Edit?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                if (RSS == DialogResult.Yes)
                {
                    Form1.service.DelOrder(Form1.order.Id);
                    Order o = new Order();

                    o.Id = Convert.ToInt32(textBox1.Text);
                    o.customer = (textBox2.Text);
                    o.StuffType = (textBox3.Text);
                    o.price = Convert.ToDouble(textBox4.Text);

                    bool flag = Form1.service.AddOrder(o);
                    if (flag)
                        MessageBox.Show("Successfully edit order");
                    else
                    {
                        MessageBox.Show("Fail edit.Order repeated");
                        Form1.service.AddOrder(temp);
                    }

                }
                else
                {
                   
                    return;
                }


            }

        }


    }
}
